/**
 * 判断必填是否为空
 * @returns {boolean}
 */
function upFilm_function_isEmpty($error) {
   let $td= $("td[style='text-align: center;color: red']");
    for(let i=0;i<$td.length;i++){
        let $children = $td.eq(i).next().children().eq(0);
       if($children.val()===""){
           $error+="必填项为空\n";
           break;
       }
    }

     return $error;
}

/**
 * 判断文件格式
 * @returns {boolean}
 */
function upFilm_function_fileType($error){
        //图片格式

    let pictName = upFilm_$table.find("input[name='pict']").val();
    let type=pictName.substring(pictName.lastIndexOf(".")+1).toUpperCase();
    if(pictType.indexOf(type)===-1){
        $error+="图片格式错误\n";
    }
    //影片格式

    let files = upFilm_$table.find("input[name='film']").get(0).files;
   for(let i=0;i<files.length;i++){
       let name = files[i].name;
       let type=name.substring(name.lastIndexOf(".")+1).toUpperCase();
       if(videoType.indexOf(type)===-1){
           $error+="第"+(i+1)+"个影片格式错误\n";

       }
   }
    return $error;
}

/**
 * 判断图片大小
 * @param $pict
 */
function upFilm_function_pictSize($pict) {

    let MyTest  = $pict.get(0).files[0];
    let reader = new FileReader();
    reader.readAsDataURL(MyTest);
    reader.onload = function (theFile) {
        let image = new Image();
        image.src = theFile.target.result;
        image.onload = function () {

               let width = image.width;
            let height = image.height;
            if(!(upFilm_w <= width && upFilm_h <= height)){
               $pict.val("");
               alert("图片尺寸错误 请重新选择图片");
            }
        };
    };

}

/**
 * 判断影片是否存在
 */
function upFilm_function_filmExist() {

    let title= upFilm_$title.val();
    let type = upFilm_$typeList.val();
    if(title!==undefined&&title!==""&&type!==undefined&&type!==""){
        $.post(
            FilmUrl+common_upFilmName+"/filmExist",
            {"title":title,
                "type":type,
                "message":"查询是否存在此影片"},
            function (data) {
                 let upFilm_filmExist=data["data"];
                 if(upFilm_filmExist){
                     //如果影片存在 则清除影片名称
                     upFilm_$title.val("");
                     alert("影片名称已存在 请重新输入");
                 }
                },
            "json"
        )
    }
}

/**
 * 判断字段长度有没有超过限制
 * @returns {boolean}
 */
function upFilm_function_sizeIndexOut($error) {
     for(let i=0;i<upFilm_$inputText.length;i++){
            let input = upFilm_$inputText.get(i);
            let value = input.value;
            let alt = input.alt;
            if(value.length>alt){
                $error+="字段长度超出限制";
                break;
            }
     }
    let val = upFilm_$textarea.val();
     if(val.length>1000){
         $error+="字段长度超出限制";
     }
    return $error;

}

/**
 * 填充主页
 */
function  upFilm_function_fillPage() {
    upFilm_$breadcrumbs.find("a").
                    attr({href:FilmUrl+common_index}).
                    parent().find("span").html("欢迎您上传影片 ");

}

/**
 * 非必填项如果为空 则设置为默认值
 */
function upFilm_function_setReleaseDate() {
    let time = "2021-10-10";
    let date = upFilm_$table.find("input[name='releaseDate']");
    if(date.val()===""){
      date.val(time);
    }
    let $td = $("td[style='text-align: center;color: blue']");
    for(let i=0;i<$td.length;i++){
        let eq = $td.eq(i).next().children().eq(0);
        if(eq.val()===""&&eq.get(0).name!=="releaseDate"){
            eq.val(eq.get(0).placeholder);
        }
    }

}

